package com.dindang.ddm.mvp.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ViewFlipper;

import com.dindang.ddm.R;
import com.dindang.ddm.mvp.model.entity.NewsList;
import com.dindang.ddm.mvp.ui.adapter.custom.AutoPollAdapter;
import com.dindang.ddm.mvp.ui.listener.AdapterListener;
import com.dindang.ddm.mvp.ui.widget.AutoPollRecyclerView;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on & 2018/10/31
 */
public class NewViewBinder extends ItemViewBinder<NewsList, NewViewBinder.ViewHolder> {

    AdapterListener listener;

    public NewViewBinder(AdapterListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_autopollrecyclerview, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull NewsList news) {
        holder.mAutoPollRecyclerView.setLayoutManager(new LinearLayoutManager(holder.mAutoPollRecyclerView.getContext(), LinearLayoutManager.VERTICAL, false));
        AutoPollAdapter mAdapter = new AutoPollAdapter(holder.mAutoPollRecyclerView.getContext(), news.getNews());
        holder.mAutoPollRecyclerView.setAdapter(mAdapter);
        holder.mAutoPollRecyclerView.start();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        AutoPollRecyclerView mAutoPollRecyclerView;
        ViewHolder(View itemView) {
            super(itemView);
            mAutoPollRecyclerView = itemView.findViewById(R.id.autopollrecyclerview);
        }
    }

}
